package com.evildog.workspace.log.application.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.evildog.workspace.common.object.PageQuery;
import com.evildog.workspace.common.result.PagedResult;
import com.evildog.workspace.dependencies.mybatis.object.QueryConditionDTO;
import com.evildog.workspace.dependencies.mybatis.util.QueryConditionUtils;
import com.evildog.workspace.log.application.bo.ExceptionLogBO;
import com.evildog.workspace.log.application.bo.ExceptionLogPageBO;
import com.evildog.workspace.log.application.convert.ExceptionLogConvert;
import com.evildog.workspace.log.application.dto.ExceptionLogDTO;
import com.evildog.workspace.log.application.dto.ExceptionLogPageDTO;
import com.evildog.workspace.log.application.entity.ExceptionLog;
import com.evildog.workspace.log.application.entity.ExceptionLogPageDO;
import com.evildog.workspace.log.application.mapper.ExceptionLogMapper;
import com.evildog.workspace.log.application.service.ExceptionLogService;
import org.springframework.stereotype.Service;
import org.springframework.util.Assert;

import java.util.List;

@Service
public class ExceptionLogServiceImpl extends ServiceImpl<ExceptionLogMapper, ExceptionLog> implements ExceptionLogService {

    @Override
    public PagedResult<ExceptionLogPageBO> getPageList(PageQuery query, List<QueryConditionDTO> queryConditions, ExceptionLogPageDTO pageDTO) {
        IPage<ExceptionLogPageDO> page = this.baseMapper.getPageList(
                QueryConditionUtils.getPagination(query),
                queryConditions,
                pageDTO);
        return ExceptionLogConvert.INSTANCE.convert(page);
    }

    @Override
    public ExceptionLogBO getDetailById(Long id) {
        ExceptionLog exceptionLog = getById(id);
        Assert.notNull(exceptionLog, "exceptionLog is null!");
        return ExceptionLogConvert.INSTANCE.convert(exceptionLog);
    }

    @Override
    public boolean save(ExceptionLogDTO dto){
        ExceptionLog newExceptionLog = ExceptionLogConvert.INSTANCE.convert(dto);
        return save(newExceptionLog);
    }

}
